<template>
  <div>
    <van-nav-bar
      title="登录"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button
          color="rgb(33, 185, 122)"
          round
          block
          type="info"
          native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  data () {
    return {
      username: '',
      password: ''
    }
  },

  created () {},

  methods: {
    async onSubmit (values) {
      try {
        console.log(1)
        const res = await axios({
          url: 'http://liufusong.top:8080/user/login',
          method: 'post',
          data: {
            username: this.username,
            password: this.password
          }
        })
        console.log(res)
        this.$router.push('/Home')
      } catch (err) {
        console.log(err)
      }
    },
    onClickLeft () {
      this.$router.push('/My')
    }
  }
}
</script>

<style scoped lang='less'>
.van-nav-bar {
  color: #fff;
  background-color: rgb(33, 185, 122);
  /deep/.van-icon-arrow-left {
    color: #fff;
  }
  /deep/.van-nav-bar__text {
    color: #fff;
  }
  /deep/.van-nav-bar__title {
    color: #fff;
  }
}
</style>
